home *** CD-ROM | disk | FTP | other *** search
/ Amiga Desktop Video CD / Amiga DeskTop Video CD.iso / install / forceicon / source / forceicon.c < prev    next >
C/C++ Source or Header  |  1994-06-23  |  26KB  |  1,005 lines

  1. /*
  2. Auto:        smake    ForceIcon
  3. */
  4.  
  5. /* $Revision Header built automatically *************** (do not edit) ************
  6. **
  7. ** © Copyright by GuntherSoft
  8. **
  9. ** File             : SnakeSYS:CPrgs/Utils/ForceIcon.c
  10. ** Created on       : Wednesday, 20.10.93 15:55:50
  11. ** Created by       : Kai Iske
  12. ** Current revision : V1.0
  13. **
  14. **
  15. ** Purpose
  16. ** -------
  17. **   - Forces Disk Icons to a specified position.
  18. **     Usefull for CD-Rom users
  19. **
  20. ** Revision V1.0
  21. ** --------------
  22. ** created on Wednesday, 20.10.93 15:55:50  by  Kai Iske.   LogMessage :
  23. **     --- Initial release ---
  24. **
  25. *********************************************************************************/
  26.  
  27.  
  28. /**********************************************************************/
  29. /*                      Routines for this module                      */
  30. /**********************************************************************/
  31. static struct    FIconSema    *FindFIconSema(void);
  32. static void            RemoveFIconSema(struct FIconSema *FIconSema);
  33. static ULONG    __saveds __asm    MyGetIcon(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase);
  34. static ULONG    __asm        DoForce(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase);
  35. static ULONG    __saveds __asm    MyLock(register __d1 UBYTE *Name, register __d2 ULONG Mode, register __a6 struct DosLibrary *DOSBase);
  36. static BOOL            OpenAll(void);
  37. static void            CloseAll(void);
  38.  
  39.  
  40.  
  41.  
  42. /**********************************************************************/
  43. /*                    Functions of files included                     */
  44. /**********************************************************************/
  45.     // LoadPrefs.h
  46.  
  47. static void            LoadPrefs(struct FIconSema *FIconSema);
  48.  
  49.     // VolList.h
  50.  
  51. static BOOL            GetDevVolList(struct List *VolList);
  52. static BOOL            GetDosEntries(struct List *VolList, ULONG Mode);
  53. static void            FreeDevVolList(struct List *VolList);
  54. static void            SortList(struct List *VolList, BOOL DisplayType);
  55. static void            SortPartialList(struct List *VolList, UWORD Left, UWORD Right);
  56. static APTR            GetListEntry(struct List *List, WORD EntryNum);
  57. static BOOL            MyStrCmp(char *FromName, char *ToName);
  58.  
  59.     // Error.h
  60.  
  61. static void    __stdargs    DisplayError(LONG ErrCode, ULONG Arg1, ...);
  62.  
  63.     // PoolVec.h
  64.  
  65. static APTR            AllocVecPool(struct FIconSema *FIconSema, ULONG Size);
  66. static void            FreeVecPool(struct FIconSema *FIconSema, APTR Addr);
  67.  
  68.  
  69.  
  70.  
  71. /**********************************************************************/
  72. /*                           Library bases                            */
  73. /**********************************************************************/
  74. struct    ExecBase        *SysBase;
  75. struct    IntuitionBase        *IntuitionBase    = NULL;
  76. struct    DosLibrary        *DOSBase    = NULL;
  77. struct    Library            *IconBase    = NULL;
  78. struct    Library            *UtilityBase    = NULL;
  79. struct    Library            *IFFParseBase    = NULL;
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. /**********************************************************************/
  87. /*                         "No-StartUp vars"                          */
  88. /**********************************************************************/
  89. static const char        _VER[]        = "\0$VER: ForceIcon "REVISION" ("REVDATE")\0";
  90. char                _ProgramName[]    = "ForceIcon";
  91. LONG                _OSERR        = 0;
  92.  
  93.  
  94.  
  95.  
  96.  
  97. /**********************************************************************/
  98. /*                           Our variables                            */
  99. /**********************************************************************/
  100. static    ULONG    __asm        (*OldGetIcon)(register __a0 UBYTE *, register __a1 struct DiskObject *, register __a2 struct FreeList *, register __a6 struct Library *);
  101. static    ULONG    __asm        (*OldLock)(register __d1 UBYTE *, register __d2 ULONG, register __a6 struct DosLibrary *);
  102. static    ULONG    __asm        (*CheckGetIcon)(register __a0 UBYTE *, register __a1 struct DiskObject *, register __a2 struct FreeList *, register __a6 struct Library *);
  103. static    ULONG    __asm        (*CheckLock)(register __d1 UBYTE *, register __d2 ULONG, register __a6 struct DosLibrary *);
  104.  
  105. static    struct    FIconSema    *FIconSema    = NULL;        // Pointer to our rendezvous semaphore
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. /**********************************************************************/
  115. /*                      This is our main program                      */
  116. /**********************************************************************/
  117. ULONG __saveds main(void)
  118. {
  119.     struct    Process        *MyProc;
  120.     struct    WBStartup    *WBenchMsg    = NULL;
  121.     BOOL            QuitIT        = FALSE;
  122.  
  123.  
  124.  
  125.         // Get SysBase
  126.  
  127.     SysBase    = *((struct ExecBase **)0x4L);
  128.  
  129.  
  130.         // Get address of our process
  131.  
  132.     MyProc = (struct Process *)FindTask(NULL);
  133.  
  134.  
  135.  
  136.         // Determine where we were started from
  137.  
  138.     if(!MyProc->pr_CLI)
  139.     {
  140.         WaitPort(&MyProc->pr_MsgPort);
  141.         WBenchMsg = (struct WBStartup *)GetMsg(&MyProc->pr_MsgPort);
  142.     }
  143.  
  144.  
  145.  
  146.         // Don`t run under OS < 37
  147.  
  148.     if(((struct Library *)SysBase)->lib_Version >= 37)
  149.     {
  150.             // Open libraries
  151.  
  152.         if(OpenAll())
  153.         {
  154.                 // Prefs Program there ???
  155.  
  156.             if((FIconSema = FindFIconSema()))
  157.             {
  158.                 Disable();
  159.                     // Patch icon.library functions
  160.  
  161.                 OldGetIcon        = (ULONG *)SetFunction(IconBase, -0x0000002a, &MyGetIcon);
  162.  
  163.                     // Patch dos.library functions
  164.  
  165.                 OldLock            = (ULONG *)SetFunction(DOSBase, -0x00000054, &MyLock);
  166.                 Enable();
  167.  
  168.  
  169.  
  170.                     // Ok, patches placed.
  171.                     // Make all connected drives diskchange
  172.  
  173.                 {
  174.                     struct    List    ChangeList;
  175.  
  176.                     ObtainSemaphore(&FIconSema->FIconSema);
  177.  
  178.                     NewList(&ChangeList);
  179.  
  180.                         // Create list of connected devices
  181.  
  182.                     if(GetDosEntries(&ChangeList, LDF_VOLUMES))
  183.                     {
  184.                         struct    DosList        *DList;
  185.                         struct    VolEntry    *ThisEntry,
  186.                                     *ListEntry;
  187.                         struct    DevProc        *DevProc;
  188.                         char            DevName[130];
  189.                         BOOL            FoundDev,
  190.                                     DoDskCh;
  191.  
  192.                         while((ThisEntry = (struct VolEntry *)RemHead(&ChangeList)))
  193.                         {
  194.                             FoundDev    = FALSE;
  195.                             DoDskCh        = FALSE;
  196.  
  197.                                 // Find name of device this volume resides in
  198.  
  199.                             if((DList = LockDosList(LDF_DEVICES|LDF_READ)))
  200.                             {
  201.                                 while((DList = NextDosEntry(DList, LDF_DEVICES|LDF_READ)))
  202.                                 {
  203.                                     if(ThisEntry->DriverTask == DList->dol_Task && !FoundDev)
  204.                                     {
  205.                                         setmem(DevName, 130, 0);
  206.                                         strncpy(DevName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  207.                                         FoundDev    = TRUE;
  208.                                     }
  209.                                 }
  210.                                 UnLockDosList(LDF_DEVICES|LDF_READ);
  211.                             }
  212.  
  213.                                 // Found corresponding device ???
  214.  
  215.                             if(FoundDev)
  216.                             {
  217.                                     // Check whether to diskchange
  218.  
  219.                                 ListEntry    = (struct VolEntry *)FIconSema->VolumeList.lh_Head;
  220.                                 while(ListEntry->Link.ln_Succ && !DoDskCh)
  221.                                 {
  222.                                     if(ListEntry->Link.ln_Type == LDF_DEVICES)
  223.                                         DoDskCh    = (MyStrCmp(ListEntry->VolName, DevName) == 0);
  224.                                     else
  225.                                         DoDskCh    = (MyStrCmp(ListEntry->VolName, ThisEntry->VolName) == 0);
  226.  
  227.                                     ListEntry = (struct VolEntry *)ListEntry->Link.ln_Succ;
  228.                                 }
  229.  
  230.                                 if(DoDskCh)
  231.                                 {
  232.                                     strcat(DevName, ":");
  233.  
  234.                                     if(ThisEntry->DriverTask && (DevProc = GetDeviceProc(DevName, NULL)))
  235.                                     {
  236.                                         if(TypeOfMem(DevProc->dvp_Port))
  237.                                         {
  238.                                             if(DoPkt(DevProc->dvp_Port, ACTION_INHIBIT, DOSTRUE, NULL, NULL, NULL, NULL))
  239.                                                 DoPkt(DevProc->dvp_Port, ACTION_INHIBIT, DOSFALSE, NULL, NULL, NULL, NULL);
  240.                                         }
  241.                                         FreeDeviceProc(DevProc);
  242.                                     }
  243.                                 }
  244.                             }
  245.  
  246.                             FreeVecPool(FIconSema, ThisEntry);
  247.                         }
  248.                     }
  249.  
  250.                     ReleaseSemaphore(&FIconSema->FIconSema);
  251.                 }
  252.  
  253.                     // Wait for termination
  254.  
  255.                 while(!QuitIT)
  256.                 {
  257.                     Wait(SIGBREAKF_CTRL_C);
  258.  
  259.                         // Ok, we are to quit
  260.  
  261.                     QuitIT    = TRUE;
  262.  
  263.  
  264.                     Disable();
  265.  
  266.                         // Try to re-install old vectors
  267.  
  268.                     CheckGetIcon    = SetFunction(IconBase, -0x0000002a, OldGetIcon);
  269.                     CheckLock    = SetFunction(DOSBase, -0x00000054, OldLock);
  270.  
  271.                     if((CheckGetIcon != &MyGetIcon) || (CheckLock != &MyLock))
  272.                     {
  273.                         QuitIT = FALSE;
  274.  
  275.                             // Re-install patches created by someone else
  276.  
  277.                         SetFunction(IconBase, -0x0000002a, CheckGetIcon);
  278.                         SetFunction(DOSBase, -0x00000054, CheckLock);
  279.                     }
  280.  
  281.                     Enable();
  282.  
  283.                     if(!QuitIT)
  284.                     {
  285.                         if((CheckGetIcon != &MyGetIcon) && (CheckLock != &MyLock))
  286.                             DisplayError(ERR_PATCHES, NULL);
  287.                         else if(CheckGetIcon != &MyGetIcon)
  288.                             DisplayError(ERR_PATCH, (ULONG)"GetIcon()", NULL);
  289.                         else
  290.                             DisplayError(ERR_PATCH, (ULONG)"Lock()", NULL);
  291.                     }
  292.                 }
  293.             }
  294.  
  295.             RemoveFIconSema(FIconSema);
  296.         }
  297.     }
  298.  
  299.  
  300.         // Close libs
  301.  
  302.     CloseAll();
  303.  
  304.  
  305.         // Send back WBStartUp Message
  306.  
  307.     if(WBenchMsg)
  308.     {
  309.         Forbid();
  310.         ReplyMsg((struct Message *)WBenchMsg);
  311.     }
  312.     return(0);
  313. }
  314.  
  315.  
  316.  
  317.  
  318. /**********************************************************************/
  319. /*                        Functionreplacements                        */
  320. /**********************************************************************/
  321. void chkabort(void){;}
  322. void __stdargs _XCEXIT(LONG Val){;}
  323.  
  324.  
  325.  
  326.  
  327.  
  328. /**********************************************************************/
  329. /*                      My new GetIcon function                       */
  330. /**********************************************************************/
  331. static ULONG __saveds __asm MyGetIcon(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase)
  332. {
  333.     struct    Process        *MyProc = (struct Process *)FindTask(NULL);
  334.     ULONG    RetVal;
  335.  
  336.         // Calling process a real process and is it Workbench ?
  337.  
  338.     if((MyProc->pr_Task.tc_Node.ln_Type == NT_PROCESS) && !strcmp(MyProc->pr_Task.tc_Node.ln_Name, "Workbench"))
  339.     {
  340.             if(!stricmp(Name, "Disk"))
  341.                 RetVal = DoForce(Name, DObj, FList, IconBase);
  342.             else
  343.                 RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  344.     }
  345.     else
  346.         RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  347.  
  348.     return(RetVal);
  349. }
  350.  
  351.  
  352.  
  353.  
  354.  
  355. /**********************************************************************/
  356. /*                       Main forcement routine                       */
  357. /**********************************************************************/
  358. static ULONG __asm DoForce(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase)
  359. {
  360.     struct    FileLock    *Dir;
  361.     struct    DosList        *DList;
  362.     char            *VolName,
  363.                 *DevName    = NULL,
  364.                 *IconName;
  365.     BPTR            MyLock,
  366.                 CheckLock;
  367.     UWORD            Left,
  368.                 Top,
  369.                 WinWidth,
  370.                 WinHeight,
  371.                 WinFlags;
  372.     WORD            WinX,
  373.                 WinY;
  374.     ULONG            RetVal        = 0;
  375.     BOOL            Found        = FALSE,
  376.                 UseAltIcon,
  377.                 UseIconPos,
  378.                 UseWindow,
  379.                 UseFlags;
  380.  
  381.  
  382.  
  383.  
  384.  
  385.         // Get our semaphore
  386.  
  387.     ObtainSemaphore(&FIconSema->FIconSema);
  388.  
  389.  
  390.         // Get buffers
  391.  
  392.     if((VolName = AllocMem(130, MEMF_CLEAR)) && (DevName = AllocMem(130, MEMF_CLEAR)))
  393.     {
  394.             // Switch to current dir
  395.  
  396.         MyLock    = CurrentDir(NULL);
  397.         Dir    = (struct FileLock *)BADDR(MyLock);
  398.         DList    = (struct DosList *)BADDR(Dir->fl_Volume);
  399.  
  400.             // Get name of volume inserted
  401.  
  402.         strncpy(VolName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  403.  
  404.             // Reset current dir
  405.  
  406.         CurrentDir(MyLock);
  407.  
  408.             // Get Name of Device
  409.  
  410.         if((DList = LockDosList(LDF_DEVICES|LDF_READ)))
  411.         {
  412.             while((DList = NextDosEntry(DList, LDF_DEVICES|LDF_READ)))
  413.             {
  414.                 if(Dir->fl_Task == DList->dol_Task)
  415.                     strncpy(DevName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  416.             }
  417.             UnLockDosList(LDF_DEVICES|LDF_READ);
  418.         }
  419.  
  420.             // Really to load from ROOT ???
  421.  
  422.         if(!(CheckLock = ParentDir(MyLock)))
  423.         {
  424.                 // Do we have patches waiting ???
  425.  
  426.             if(!IsListEmpty(&FIconSema->VolumeList))
  427.             {
  428.                 struct    VolEntry    *ThisEntry = (struct VolEntry *)FIconSema->VolumeList.lh_Head;
  429.  
  430.                 do
  431.                 {
  432.                         // This one to patch ???
  433.  
  434.                     if(ThisEntry->Link.ln_Type == LDF_DEVICES && !MyStrCmp(ThisEntry->VolName, DevName))
  435.                         Found = TRUE;
  436.  
  437.                     else if(ThisEntry->Link.ln_Type == LDF_VOLUMES && !MyStrCmp(ThisEntry->VolName, VolName))
  438.                         Found = TRUE;
  439.  
  440.                     else
  441.                         ThisEntry = (struct VolEntry *)ThisEntry->Link.ln_Succ;
  442.  
  443.                 } while(!Found && ThisEntry->Link.ln_Succ);
  444.  
  445.                     // Object to be patched ?
  446.  
  447.                 if(Found)
  448.                 {
  449.                         // Set vars for icon substitution
  450.  
  451.                     UseAltIcon    = (ThisEntry->UseAlt == MODE_USE);
  452.                     IconName    = ThisEntry->IconName;
  453.  
  454.                         // Set vars for icon placement
  455.  
  456.                     UseIconPos    = (ThisEntry->IconPos == MODE_USE);
  457.                     Left        = ThisEntry->Left;
  458.                     Top        = ThisEntry->Top;
  459.  
  460.                         // Set vars for window settings
  461.  
  462.                     UseWindow    = (ThisEntry->UseWin == MODE_USE);
  463.                     WinX        = ThisEntry->WinX;
  464.                     WinY        = ThisEntry->WinY;
  465.                     WinWidth    = ThisEntry->WinWidth;
  466.                     WinHeight    = ThisEntry->WinHeight;
  467.  
  468.                         // Set vars for window flags
  469.  
  470.                     UseFlags    = (ThisEntry->UseFlags == MODE_USE);
  471.                     WinFlags    = ThisEntry->WinFlags;
  472.  
  473.  
  474.                         // This entry a volume and are we allowed to obtain settings from device ???
  475.  
  476.                     if(ThisEntry->Link.ln_Type == LDF_VOLUMES)
  477.                     {
  478.                         struct    VolEntry    *DevEntry    = (struct VolEntry *)FIconSema->VolumeList.lh_Head;
  479.                         BOOL            FoundMyDev    = FALSE;
  480.  
  481.                             // Search for device-entry corresponding to volume
  482.  
  483.                         while(DevEntry->Link.ln_Succ && !FoundMyDev)
  484.                         {
  485.                             if(DevEntry->Link.ln_Type == LDF_DEVICES && !MyStrCmp(DevEntry->VolName, DevName))
  486.                                 FoundMyDev    = TRUE;
  487.                             else
  488.                                 DevEntry    = (struct VolEntry *)DevEntry->Link.ln_Succ;
  489.                         }
  490.  
  491.                             // Got a device entry for this volume ???
  492.  
  493.                         if(FoundMyDev)
  494.                         {
  495.                                 // Use alternative icon for volume ???
  496.  
  497.                             if(ThisEntry->UseAlt == MODE_INHERIT)
  498.                             {
  499.                                     // no, use one for device entry ???
  500.                                     // If so, set pointer to new iconname
  501.  
  502.                                 if(DevEntry->UseAlt == MODE_USE)
  503.                                 {
  504.                                     UseAltIcon    = TRUE;
  505.                                     IconName    = DevEntry->IconName;
  506.                                 }
  507.                             }
  508.  
  509.                                 // Use alternative position for volume ???
  510.  
  511.                             if(ThisEntry->IconPos == MODE_INHERIT)
  512.                             {
  513.                                     // no, use one for device entry ???
  514.                                     // if so, set vars
  515.  
  516.                                 if(DevEntry->IconPos == MODE_USE)
  517.                                 {
  518.                                     UseIconPos    = TRUE;
  519.                                     Left        = DevEntry->Left;
  520.                                     Top        = DevEntry->Top;
  521.                                 }
  522.                             }
  523.  
  524.                                 // Use settings of window ???
  525.  
  526.                             if(ThisEntry->UseWin == MODE_INHERIT)
  527.                             {
  528.                                     // no, use one for device entry ???
  529.                                     // if so, set vars
  530.  
  531.                                 if(DevEntry->UseWin == MODE_USE)
  532.                                 {
  533.                                     UseWindow    = TRUE;
  534.                                     WinX        = DevEntry->WinX;
  535.                                     WinY        = DevEntry->WinY;
  536.                                     WinWidth    = DevEntry->WinWidth;
  537.                                     WinHeight    = DevEntry->WinHeight;
  538.                                 }
  539.                             }
  540.  
  541.                                 // Use settings of flags
  542.  
  543.                             if(ThisEntry->UseFlags == MODE_INHERIT)
  544.                             {
  545.                                     // no, use one for device entry ???
  546.                                     // if so, set vars
  547.  
  548.                                 if(DevEntry->UseFlags == MODE_USE)
  549.                                 {
  550.                                     UseFlags    = TRUE;
  551.                                     WinFlags    = DevEntry->WinFlags;
  552.                                 }
  553.                             }
  554.                         }
  555.                     }
  556.  
  557.  
  558.                         // Alternative icon ???
  559.  
  560.                     if(UseAltIcon)
  561.                     {
  562.                         char    *EndPtr;
  563.  
  564.                             // Check for name and remove extension
  565.  
  566.                         strcpy(VolName, IconName);
  567.                         strlwr(VolName);
  568.                         if((EndPtr = strstr(VolName, ".info")))
  569.                         {
  570.                             BPTR    TestLock;
  571.  
  572.                             setmem(VolName, 130, 0);
  573.                             strncpy(VolName, IconName, (EndPtr - VolName));
  574.  
  575.                                 // Try to get supplied name
  576.  
  577.                             if((TestLock = Lock(IconName, ACCESS_READ)))
  578.                             {
  579.                                 UnLock(TestLock);
  580.  
  581.                                     // Try to read in this icon
  582.  
  583.                                 if(!(RetVal = OldGetIcon(VolName, DObj, FList, IconBase)))
  584.                                     RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  585.                                 else
  586.                                 {
  587.                                     BOOL    GotData    = FALSE;
  588.  
  589.                                         // Ok, we`ve loaded a new icon, so set appropriate flags ;)
  590.  
  591.                                     if(DObj->do_Type == WBTOOL || DObj->do_Type == WBPROJECT)
  592.                                     {
  593.                                             // Try to set drawerdata for tool and project icons
  594.  
  595.                                         if((DObj->do_DrawerData = AllocMem(sizeof(struct DrawerData), MEMF_CLEAR|MEMF_PUBLIC)))
  596.                                             GotData    = TRUE;
  597.                                     }
  598.                                     else
  599.                                         GotData = TRUE;
  600.  
  601.                                     if(GotData)
  602.                                     {
  603.                                         struct    DrawerData    *DDat = DObj->do_DrawerData;
  604.  
  605.                                             // Fill in structure
  606.  
  607.                                         DDat->dd_NewWindow.LeftEdge    = ThisEntry->LeftEdge;
  608.                                         DDat->dd_NewWindow.TopEdge    = ThisEntry->TopEdge;
  609.                                         DDat->dd_NewWindow.Width    = ThisEntry->Width;
  610.                                         DDat->dd_NewWindow.Height    = ThisEntry->Height;
  611.                                         DDat->dd_NewWindow.DetailPen    = 255;
  612.                                         DDat->dd_NewWindow.BlockPen    = 255;
  613.                                         DDat->dd_NewWindow.Flags    = WFLG_HASZOOM|WFLG_WINDOWTICKED|WFLG_REPORTMOUSE|WFLG_SIMPLE_REFRESH|WFLG_SIZEBRIGHT|WFLG_SIZEBBOTTOM|WFLG_CLOSEGADGET|WFLG_DEPTHGADGET|WFLG_DRAGBAR|WFLG_SIZEGADGET;
  614.                                         DDat->dd_NewWindow.MinWidth    = 90;
  615.                                         DDat->dd_NewWindow.MinHeight    = 40;
  616.                                         DDat->dd_NewWindow.MaxWidth    = 0xffff;
  617.                                         DDat->dd_NewWindow.MaxHeight    = 0xffff;
  618.                                         DDat->dd_NewWindow.Type        = WBENCHSCREEN;
  619.                                         DDat->dd_CurrentX        = ThisEntry->CurrentX;
  620.                                         DDat->dd_CurrentY        = ThisEntry->CurrentY;
  621.                                         DDat->dd_Flags            = ThisEntry->Flags;
  622.                                         DDat->dd_ViewModes        = ThisEntry->ViewMode;
  623.  
  624.                                             // A Ok, set new type of icon
  625.  
  626.                                         DObj->do_Type = WBDISK;
  627.                                     }
  628.                                 }
  629.                             }
  630.                             else
  631.                                 RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  632.                         }
  633.                         else
  634.                             RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  635.                     }
  636.                     else
  637.                         RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  638.  
  639.                     if(RetVal)
  640.                     {
  641.                         struct    Screen    *WBScreen    = LockPubScreen("Workbench");
  642.  
  643.                             // Patch position ???
  644.  
  645.                         if(WBScreen)
  646.                         {
  647.                                 // Do so
  648.  
  649.                             DObj->do_CurrentX = (UseIconPos) ? Left : NO_ICON_POSITION;
  650.                             DObj->do_CurrentY = (UseIconPos) ? Top - WBScreen->BarHeight - 1 : NO_ICON_POSITION;
  651.  
  652.                             UnlockPubScreen(NULL, WBScreen);
  653.                         }
  654.  
  655.                             // Use window ???
  656.  
  657.                         if(UseWindow)
  658.                         {
  659.                             DObj->do_DrawerData->dd_NewWindow.LeftEdge    = WinX;
  660.                             DObj->do_DrawerData->dd_NewWindow.TopEdge    = WinY;
  661.                             DObj->do_DrawerData->dd_NewWindow.Width        = WinWidth;
  662.                             DObj->do_DrawerData->dd_NewWindow.Height    = WinHeight;
  663.                         }
  664.  
  665.                             // Set Flags ???
  666.  
  667.                         if(UseFlags)
  668.                         {
  669.                             DObj->do_DrawerData->dd_Flags            = (WinFlags > 3 ? 2 : 0);
  670.                             DObj->do_DrawerData->dd_ViewModes        = (WinFlags > 3 ? WinFlags - 3 : WinFlags + 1);
  671.                         }
  672.                     }
  673.                 }
  674.             }
  675.         }
  676.         else
  677.             UnLock(CheckLock);
  678.     }
  679.  
  680.     if(VolName)
  681.         FreeMem(VolName, 130);
  682.  
  683.     if(DevName)
  684.         FreeMem(DevName, 130);
  685.  
  686.  
  687.         // No entry found and not the orig. icon read -> use supplied name
  688.  
  689.     if(!Found && !RetVal)
  690.         RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  691.  
  692.         // Release that fine semaphore
  693.  
  694.     ReleaseSemaphore(&FIconSema->FIconSema);
  695.  
  696.     return(RetVal);
  697. }
  698.  
  699.  
  700.  
  701.  
  702.  
  703. /**********************************************************************/
  704. /*                        My new Lock routine                         */
  705. /**********************************************************************/
  706. static ULONG __saveds __asm MyLock(register __d1 UBYTE *Name, register __d2 ULONG Mode, register __a6 struct DosLibrary *DOSBase)
  707. {
  708.     struct    Process        *MyProc        = (struct Process *)FindTask(NULL);
  709.     struct    FileLock    *Dir;
  710.     struct    DosList        *DList;
  711.     char            *VolName,
  712.                 *DevName    = NULL,
  713.                 *IconName;
  714.     BPTR            MyLock,
  715.                 CheckLock;
  716.     ULONG            RetVal        = NULL;
  717.     BOOL            Found        = FALSE,
  718.                 UseAltIcon;
  719.  
  720.  
  721.  
  722.         // Get buffers
  723.  
  724.     if((VolName = AllocMem(130, MEMF_CLEAR|MEMF_PUBLIC)) && (DevName = AllocMem(130, MEMF_CLEAR|MEMF_PUBLIC)))
  725.     {
  726.             // Calling process a real process and is it Workbench ?
  727.  
  728.         if((MyProc->pr_Task.tc_Node.ln_Type == NT_PROCESS) && TypeOfMem(MyProc->pr_Task.tc_Node.ln_Name) && !strcmp(MyProc->pr_Task.tc_Node.ln_Name, "Workbench"))
  729.         {
  730.  
  731.                 // Trying to load a Disk.info ???
  732.  
  733.             if(TypeOfMem(Name) && !stricmp(Name, "Disk.info"))
  734.             {
  735.                     // Get my semaphore
  736.  
  737.                 ObtainSemaphore(&FIconSema->FIconSema);
  738.  
  739.                     // Switch to current dir
  740.  
  741.                 MyLock    = CurrentDir(NULL);
  742.                 Dir    = (struct FileLock *)BADDR(MyLock);
  743.                 DList    = (struct DosList *)BADDR(Dir->fl_Volume);
  744.  
  745.                     // Get name of volume inserted
  746.  
  747.                 strncpy(VolName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  748.  
  749.                     // Reset current dir
  750.  
  751.                 CurrentDir(MyLock);
  752.  
  753.                     // Get Name of Device
  754.  
  755.                 if((DList = LockDosList(LDF_DEVICES|LDF_READ)))
  756.                 {
  757.                     while((DList = NextDosEntry(DList, LDF_DEVICES|LDF_READ)))
  758.                     {
  759.                         if(Dir->fl_Task == DList->dol_Task)
  760.                             strncpy(DevName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  761.                     }
  762.                     UnLockDosList(LDF_DEVICES|LDF_READ);
  763.                 }
  764.  
  765.                     // Really load from ROOT ?
  766.  
  767.                 if(!(CheckLock = ParentDir(MyLock)))
  768.                 {
  769.                         // Do we have patches waiting ???
  770.  
  771.                     if(!IsListEmpty(&FIconSema->VolumeList))
  772.                     {
  773.                         struct    VolEntry    *ThisEntry = (struct VolEntry *)FIconSema->VolumeList.lh_Head;
  774.  
  775.                         do
  776.                         {
  777.                                 // This one to patch ???
  778.  
  779.                             if(ThisEntry->Link.ln_Type == LDF_DEVICES && !MyStrCmp(ThisEntry->VolName, DevName))
  780.                                 Found = TRUE;
  781.  
  782.                             else if(ThisEntry->Link.ln_Type == LDF_VOLUMES && !MyStrCmp(ThisEntry->VolName, VolName))
  783.                                 Found = TRUE;
  784.  
  785.                             else
  786.                                 ThisEntry = (struct VolEntry *)ThisEntry->Link.ln_Succ;
  787.  
  788.                         } while(!Found && ThisEntry->Link.ln_Succ);
  789.  
  790.                             // Object to be patched ?
  791.  
  792.                         if(Found)
  793.                         {
  794.                                 // Set vars for icon substitution
  795.  
  796.                             UseAltIcon    = (ThisEntry->UseAlt == MODE_USE);
  797.                             IconName    = ThisEntry->IconName;
  798.  
  799.                                 // This entry a volume and are we allowed to obtain settings from a device ???
  800.  
  801.                             if(ThisEntry->Link.ln_Type == LDF_VOLUMES)
  802.                             {
  803.                                 struct    VolEntry    *DevEntry    = (struct VolEntry *)FIconSema->VolumeList.lh_Head;
  804.                                 BOOL            FoundMyDev    = FALSE;
  805.  
  806.                                     // Search for device-entry corresponding to volume
  807.  
  808.                                 while(DevEntry->Link.ln_Succ && !FoundMyDev)
  809.                                 {
  810.                                     if(DevEntry->Link.ln_Type == LDF_DEVICES && !MyStrCmp(DevEntry->VolName, DevName))
  811.                                         FoundMyDev    = TRUE;
  812.                                     else
  813.                                         DevEntry    = (struct VolEntry *)DevEntry->Link.ln_Succ;
  814.                                 }
  815.  
  816.                                     // Got a device entry for this volume ???
  817.  
  818.                                 if(FoundMyDev)
  819.                                 {
  820.                                         // Use alternative icon for volume ???
  821.  
  822.                                     if(ThisEntry->UseAlt == MODE_INHERIT)
  823.                                     {
  824.                                             // no, use one for device entry ???
  825.                                             // If so, set pointer to new iconname
  826.  
  827.                                         if(DevEntry->UseAlt == MODE_USE)
  828.                                         {
  829.                                             UseAltIcon    = TRUE;
  830.                                             IconName    = DevEntry->IconName;
  831.                                         }
  832.                                     }
  833.                                 }
  834.                             }
  835.  
  836.                                 // If an alternative icon is to be used
  837.                                 // lock this one, otherwise lock Disk.info
  838.  
  839.                             if(UseAltIcon)
  840.                             {
  841.                                 struct    DiskObject    *OldDiskObject;
  842.                                 WORD    OldLeft        = 50,
  843.                                     OldTop        = 50,
  844.                                     OldWidth     = 400,
  845.                                     OldHeight    = 100;
  846.                                 LONG    OldCurrentX    = 0,
  847.                                     OldCurrentY    = 0;
  848.                                 ULONG    OldFlags    = 0x0;
  849.                                 UWORD    OldViewMode    = 1;
  850.  
  851.                                 if(!(RetVal = OldLock(IconName, Mode, DOSBase)))
  852.                                     RetVal = OldLock(Name, Mode, DOSBase);
  853.                                 else
  854.                                 {
  855.                                         // Get original Disk.info file, in order to obtain
  856.                                         // the correct window position and size
  857.  
  858.                                     strcat(DevName, ":Disk");
  859.                                     if(!(OldDiskObject = GetDiskObject(DevName)))
  860.                                     {
  861.                                         strcat(VolName, ":Disk");
  862.                                         OldDiskObject = GetDiskObject(VolName);
  863.                                     }
  864.  
  865.                                     if(OldDiskObject)
  866.                                     {
  867.                                         OldLeft        = OldDiskObject->do_DrawerData->dd_NewWindow.LeftEdge;
  868.                                         OldTop        = OldDiskObject->do_DrawerData->dd_NewWindow.TopEdge;
  869.                                         OldWidth    = OldDiskObject->do_DrawerData->dd_NewWindow.Width;
  870.                                         OldHeight    = OldDiskObject->do_DrawerData->dd_NewWindow.Height;
  871.                                         OldCurrentX    = OldDiskObject->do_DrawerData->dd_CurrentX;
  872.                                         OldCurrentY    = OldDiskObject->do_DrawerData->dd_CurrentY;
  873.                                         OldFlags    = OldDiskObject->do_DrawerData->dd_Flags;
  874.                                         OldViewMode    = OldDiskObject->do_DrawerData->dd_ViewModes;
  875.  
  876.                                         FreeDiskObject(OldDiskObject);
  877.                                     }
  878.  
  879.                                     ThisEntry->LeftEdge    = OldLeft;
  880.                                     ThisEntry->TopEdge    = OldTop;
  881.                                     ThisEntry->Width    = OldWidth;
  882.                                     ThisEntry->Height    = OldHeight;
  883.                                     ThisEntry->CurrentX    = OldCurrentX;
  884.                                     ThisEntry->CurrentY    = OldCurrentY;
  885.                                     ThisEntry->Flags    = OldFlags;
  886.                                     ThisEntry->ViewMode    = OldViewMode;
  887.                                 }
  888.                             }
  889.                             else
  890.                                 Found = FALSE;
  891.                         }
  892.                     }
  893.                 }
  894.                 else
  895.                     UnLock(CheckLock);
  896.  
  897.                 ReleaseSemaphore(&FIconSema->FIconSema);
  898.             }
  899.         }
  900.     }
  901.  
  902.     if(VolName)
  903.         FreeMem(VolName, 130);
  904.  
  905.     if(DevName)
  906.         FreeMem(DevName, 130);
  907.  
  908.  
  909.     if(!Found)
  910.         RetVal = OldLock(Name, Mode, DOSBase);
  911.  
  912.     return(RetVal);
  913. }
  914.  
  915.  
  916.  
  917.  
  918.  
  919. /**********************************************************************/
  920. /*                           Open libraries                           */
  921. /**********************************************************************/
  922. static BOOL OpenAll(void)
  923. {
  924.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37)))
  925.     {
  926.         DisplayError(ERR_OPEN, (ULONG)"intuition.library", 37);
  927.         return(FALSE);
  928.     }
  929.  
  930.     if(!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37)))
  931.     {
  932.         DisplayError(ERR_OPEN, (ULONG)"dos.library", 37);
  933.         return(FALSE);
  934.     }
  935.  
  936.     if(!(IconBase = OpenLibrary("icon.library", 37)))
  937.     {
  938.         DisplayError(ERR_OPEN, (ULONG)"icon.library", 37);
  939.         return(FALSE);
  940.     }
  941.  
  942.     if(!(UtilityBase = OpenLibrary("utility.library", 37)))
  943.     {
  944.         DisplayError(ERR_OPEN, (ULONG)"utility.library", 37);
  945.         return(FALSE);
  946.     }
  947.  
  948.     if(!(IFFParseBase = OpenLibrary("iffparse.library", 37)))
  949.     {
  950.         DisplayError(ERR_OPEN, (ULONG)"iffparse.library", 37);
  951.         return(FALSE);
  952.     }
  953.  
  954.     if(!(AslBase = OpenLibrary("asl.library", 36)))
  955.     {
  956.         DisplayError(ERR_OPEN, (ULONG)"asl.library", 36);
  957.         return(FALSE);
  958.     }
  959.  
  960.     return(TRUE);
  961. }
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970. /**********************************************************************/
  971. /*                          Close libraries                           */
  972. /**********************************************************************/
  973. static void CloseAll(void)
  974. {
  975.     if(AslBase)
  976.         CloseLibrary(AslBase);
  977.  
  978.     if(IFFParseBase)
  979.         CloseLibrary(IFFParseBase);
  980.  
  981.     if(UtilityBase)
  982.         CloseLibrary(UtilityBase);
  983.  
  984.     if(IconBase)
  985.         CloseLibrary(IconBase);
  986.  
  987.     if(DOSBase)
  988.         CloseLibrary((struct Library *)DOSBase);
  989.  
  990.     if(IntuitionBase)
  991.         CloseLibrary((struct Library *)IntuitionBase);
  992. }
  993.  
  994.  
  995.  
  996.  
  997. /**********************************************************************/
  998. /*       Now include the LoadRoutine and the VolumeList routine       */
  999. /**********************************************************************/
  1000. #include    "LoadPrefs.h"
  1001. #include    "VolList.h"
  1002. #include    "Error.h"
  1003. #include    "Rendezvous.h"
  1004. #include    "PoolVec.h"
  1005.